package com.supermap.search.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.supermap.greendao.XunJianOneTimeDao;
import com.supermap.search.R;
import com.supermap.search.adapter.MyAdapter;
import com.supermap.search.javabean.XunJianOneTime;
import com.supermap.search.sys.loc.LocationApplication;
import com.supermap.search.utils.SpUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 未上传维修的界面
 * Created by XueQing Wang on 2018/6/29.
 */

public class NoUpWeiXiuActivity extends AppCompatActivity {
    @BindView(R.id.tv_allclear)
    TextView tvAllclear;
    @BindView(R.id.lv_weishangchuan)
    ListView lvWeishangchuan;


    //初始化巡检dao
    private XunJianOneTimeDao dao;
    private List<XunJianOneTime> xunJianOneTimes;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_noshangchuanweixiu);
        ButterKnife.bind(this);
        initdata();
    }

    private void initdata() {
        dao = LocationApplication.getInstance().getDaoSession().getXunJianOneTimeDao();
        xunJianOneTimes = dao.loadAll();
        for(int i=0;i<xunJianOneTimes.size();i++){
            XunJianOneTime xunJianOneTime = xunJianOneTimes.get(i);
            String state = xunJianOneTime.getState();
            if(!"3".equals(state)){
//                xunJianOneTimes.remove(i);
            }
        }
        if (xunJianOneTimes != null && xunJianOneTimes.size() > 0) {
            //不為空
            lvWeishangchuan.setVisibility(View.VISIBLE);
            tvAllclear.setVisibility(View.GONE);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    MyAdapter<XunJianOneTime> adapter = new MyAdapter<XunJianOneTime>(xunJianOneTimes, R.layout.item_lv_noshangchuanyanzheng){

                        @Override
                        public void bindView(MyAdapter.ViewHolder holder, XunJianOneTime obj) {

                            holder.setImageUrl(R.id.iv_noupxunjian,SpUtils.stringToList(obj.getPhotopath()).get(0));
                            holder.setText(R.id.tv_yanzhongchengdu,"严重程度:" + obj.getYanzhongchengdu());
                            holder.setText(R.id.tv_wentiqingkuang,"问题情况:" + obj.getWentiqingkuang());
                            holder.setText(R.id.tv_reportTime,"上报时间:"+obj.getReportTime());
                            holder.setText(R.id.tv_repairTime,"维修时间:"+obj.getRepairTime());
                            holder.setText(R.id.tv_weixiumiaoshu,"维修描述:"+obj.getRepairDesc());
                        }
                    };
                    lvWeishangchuan.setAdapter(adapter);
                    lvWeishangchuan.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Intent intent = new Intent(NoUpWeiXiuActivity.this, WenTiXiangQingActivity.class);
                                    Bundle bundle = new Bundle();
                                    bundle.putSerializable("user", xunJianOneTimes.get(position));
                                    intent.putExtras(bundle);
                                    startActivity(intent);
                                }
                            });
                        }
                    });
                }
            }).start();

        } else {
            lvWeishangchuan.setVisibility(View.GONE);
            tvAllclear.setVisibility(View.VISIBLE);
        }

    }
}
